#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "algorithm_search.h"
#include "algorithm_sort.h"

#ifndef TRUE 
#define TRUE 1
#endif

#define SIZE_OF_BUFFER 1024

int wildcard_matches(const char *wildcard, const char *str) 
{
    printf("pattern: %c, string %c\n", *wildcard, *str);
    if (*wildcard == '\0')
        return *str == '\0';
    if (*wildcard == '?')
        return wildcard_matches(++wildcard, ++str);
    else if (*wildcard == '*') 
    {
        for (++wildcard; *str; ++str)
        {
            if (wildcard_matches(wildcard, str))
            {
                return TRUE;
            }
        }
        return *wildcard == '\0';
    } 
    else
    {
        return *wildcard == *str && wildcard_matches(++wildcard, ++str);
    }
}


int main(int argc, char **argv)
{
    int match_ret;
    char src[] = "a.txt";
    char *pattern = (char *)malloc(SIZE_OF_BUFFER * sizeof(char));

    match_ret = wildcard_matches("*bb.txt", "abbcbb.txt");

    if (NULL == pattern)
    {
        return 1;
    }

    //match_ret = WildcardMatch("abc", "*.txt", false, true);

    //match_ret = WildcardMatch("abc", "*.txt", true, true);

    //match_ret = WildcardMatch("abc.txt", "*.txt", true, true);
    //
    //strcpy_s(pattern, SIZE_OF_BUFFER, "?.txt");

    //match_ret = WildcardMatch(src, pattern, false, true);

    //strcpy_s(pattern, SIZE_OF_BUFFER, "*.txt");

    //match_ret = WildcardMatch(src, pattern, false, true);

    //strcpy_s(pattern, SIZE_OF_BUFFER, "*.*");

    //match_ret = WildcardMatch(src, pattern, false, true);

    //match_ret = WildcardMatch("Aaaa", "a*a", false, true);

    //match_ret = WildcardMatch("ABBCBCCC.TXT", "A*BC??.TXT", false, true);


    free(pattern);
    pattern = NULL;

    return 0;
}